using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library.Definitions;
using NCS.Library;
using NCS.Module.CMS.Library.Distributions;
using NCS.Library.Components.Partner;
using NCS.Module.CMS.Library.Zones;

namespace NCS.Module.CMS.Web.HomePage
{
    public partial class LeftNewNews : CMSWebControl
    {
        public int zoneid;
        protected void Page_Load(object sender, EventArgs e)
        {
            //int defaultvalue = AppEnv.GetLanguage() == "vi-VN" ? 420 : 335;
            //string portalactive = this.Portal[Definition.Portal_Active + "_" + AppEnv.GetLanguage()].ToString();
            //this.zoneid = ConvertUtility.ToInt32(this.Portal[Definition.Portal_Zone_Active + "_" + portalactive + "_" + AppEnv.GetLanguage()], defaultvalue);
            //this.zoneid = ConvertUtility.ToInt32(this.Portal[Definition.Portal_Zone_Active + "_" + portalactive + "_" + AppEnv.GetLanguage()], defaultvalue);
            //DataTable tblist = DistributionController.GetDistributedContents(zoneid, 3, (int)CMSDistributionRank.Default);
            int total;
            //DataTable tblist = DistributionController.GetNewContentByZoneIDAndRank(zoneid, true, 3, 0, out total);
            DataTable tblist = DistributionController.Distributions_GetHotNews(3, AppEnv.PortalId()); //DistributionController.Distributions_GetNewContent(3, AppEnv.PortalId());

            rptLastestNews.DataSource = tblist;
            rptLastestNews.ItemDataBound += new RepeaterItemEventHandler(rptLastestNews_ItemDataBound);
            rptLastestNews.DataBind();
        }

        void rptLastestNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemIndex >= 0)
            {
                DataRowView row = (DataRowView)e.Item.DataItem;
                HyperLink link = (HyperLink)e.Item.FindControl("link1");
                link.NavigateUrl = BuildUrlByDistId(ConvertUtility.ToInt32(row["Distribution_ID"]), (int)row["Distribution_ZoneID"], AppEnv.PortalId());
                link.Text = ConvertUtility.ToString(row["Content_Headline"]);
                //link.Text = link.Text.Length > 80 ? link.Text.Substring(0, 80) + "..." : link.Text;
            }
        }
    }
}